package com.van.oauth.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * 访问swagger  http://localhost:{post}/swagger-ui/
 * 访问knife4j  http://localhost:{post}/doc.html
 * @author VanKa qq:2395073039
 * @date 2021/8/17 16:13
 */
@Configuration
@EnableKnife4j
public class SwaggerConfig {
    @Value("${spring.application.name}")
    private String projectName;
    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 构建api文档的详细信息函数
     * @return 作者信息
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                //页面标题
                .title( projectName + " API接口文档")
                //创建人
                .contact(new Contact("VanKa", "https://gitee.com/vankana", "2395073039@qq.com"))
                .version("1.0")//版本号
                .description("oauth 注册中心")//描述
                .build();
    }
}